package guoanmaker.operator.business.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import guoanmaker.operator.business.model.OperatorLuckdraw;
import guoanmaker.operator.business.model.OperatorSecckill;

public interface OperatorSecckillRepository extends JpaRepository<OperatorSecckill, String>, JpaSpecificationExecutor<OperatorSecckill> {
	@Query("select osk from OperatorSecckill osk where osk.activityId=:activityId ")
	public List<OperatorSecckill> queryAllOperatorSecckillByActivityId(@Param("activityId")String activityId);
	
	@Query("select osk from OperatorSecckill osk where osk.commodId=:commodId AND  osk.skStartTime <= now() AND osk.skEndTime>= now()")
	public OperatorSecckill selectOperatorSecckillByCommodId(@Param("commodId")String commodId);
	@Transactional
	@Modifying
	@Query("DELETE FROM OperatorSecckill where skStartTime=:skTime ")
	public void deleteOperatorSecckillByTime(@Param("skTime")Date skTime);
}
